package entity

import (
	"strconv"
	"time"

	"shqsoft.cn/pasnj/base"
	"shqsoft.cn/pasnj/bi/cube"
)

//对公存款
type COMP_LOAN struct {
	ID   int        `gorm:"AUTO_INCREMENT;primary_key;column:ID"`
	KHMC string     `gorm:"column:客户名称"`
	ZH   string     `gorm:"column:帐户;"`
	KHWD string     `gorm:"column:开户网点;"`
	KHRQ *time.Time `gorm:"column:开户日期;type:date;"`
	QXR  *time.Time `gorm:"column:起息日;type:date;"`
	DQR  *time.Time `gorm:"column:到期日;type:date;"`
	QYGM string     `gorm:"column:企业规模;"`
	QYLX int32      `gorm:"column:QYLX;"`
	KM   string     `gorm:"column:科目;"`
	DQYE *float64   `gorm:"column:当前余额"`
	INRT *float64   `gorm:"column:利率"`
	BZ   string     `gorm:"column:币种;"`
	KHRJ *float64   `gorm:"column:开户日均;"`
	YG1  string     `gorm:"-"`
	ZB1  *float64   `gorm:"-"`
	YG2  string     `gorm:"-"`
	ZB2  *float64   `gorm:"-"`
	YG3  string     `gorm:"-"`
	ZB3  *float64   `gorm:"-"`
	YG4  string     `gorm:"-"`
	ZB4  *float64   `gorm:"-"`
	YG5  string     `gorm:"-"`
	ZB5  *float64   `gorm:"-"`
}

//Country 国家
type Country struct {
	ID   int    `gorm:"primary_key;column:ID"`
	Name string `gorm:"column:LXMC;size:20"`
}

//Country 国家
func (Country) TableName() string {
	return "T_CONF_GJLX"
}

// AfterFind 选择男女
func (c *COMP_LOAN) AfterFind() (err error) {
	var share *cube.Share
	share, err = cube.GetShare("comp_acco_divi")
	if err != nil {
		return
	}
	var diviMap map[string]float64
	diviMap, err = share.GetDivision(strconv.Itoa(c.ID))
	if err != nil {
		return
	}
	i := 0
	for k, v := range diviMap {
		val := v
		i++
		switch i {
		case 1:
			c.YG1 = k
			c.ZB1 = &val
		case 2:
			c.YG2 = k
			c.ZB2 = &val
		case 3:
			c.YG3 = k
			c.ZB3 = &val
		case 4:
			c.YG4 = k
			c.ZB4 = &val
		case 5:
			c.YG5 = k
			c.ZB5 = &val
		default:
			break
		}
	}
	return
}

// PositionEF 返回一个机构体
func CountryEF() base.EntityFunc {
	return func() interface{} {
		entity := Country{}
		return &entity
	}
}

// PositionESF 返回一个机构体数组
func CountryESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []Country
		return &entities
	}
}

//TableName 表名
func (COMP_LOAN) TableName() string {
	return "V_COMP_LOAN"
}

func COMP_LOANEF() base.EntityFunc {
	return func() interface{} {
		entity := COMP_LOAN{}
		return &entity
	}
}
func COMP_LOANESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []COMP_LOAN
		return &entities
	}
}

func init() {
	base.DaoPoolObj.Put("Country", base.NewDefaultDao(CountryEF(), CountryESF(), nil))
	dao := base.NewDefaultDao(COMP_LOANEF(), COMP_LOANESF(), nil)
	filter := base.DefaultFilter{
		FilterColName: "ID",
		TableName:     "t_comp_acco_divi",
		EmidColName:   "emid",
		AcidColName:   "acid",
		WhereCause:    "iswo=0 and wodt is null",
	}
	dao.Fileter = &filter
	base.DaoPoolObj.Put("COMP_LOAN", dao)
}
